﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BLL.BussinessClass;
using Model;

namespace AlltrustDinner.Pages.Admin
{
    /// <summary>
    /// UserManagementProcess 的摘要说明
    /// </summary>
    public class UserManagementProcess : HttpHandlerProcess, IHttpHandler
    {
        private string result;
        public void ProcessRequest(HttpContext context)
        {
            this.GetQueryParam(context);
            switch (cmd)
            {
                case "UpdateUser":
                    result = this.UpdateUser(queryParam["user_info"]);
                    break;
                default:
                    break;
            }
            context.Response.ContentType = "text/plain";
            context.Response.Write(this.Serializer.Serialize(result));
        }

        private string UpdateUser(Dictionary<string, string> para)
        {

            UserBiz biz = new UserBiz();
            decimal balanceChange = 0;
            USER user = biz.GetUser(para["lbl_id"]);
            if (user == null)
            {
                return "0";
            }
            if (!string.IsNullOrEmpty(para["ipt_balance_change"].Trim()) && !decimal.TryParse(para["ipt_balance_change"], out balanceChange))
            {
                return "0";
            }

            user.ID = para["lbl_id"];
            user.NAME = para["lbl_name"];
            user.BALANCE += balanceChange;
            user.RIGHT = int.Parse(para["ddl_right"]);
            return biz.UpdateUser(user).ToString();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}